package com.jty.lib_base.room.dao

import androidx.room.*
import com.jty.lib_base.room.bean.GridPicture

@Dao
interface GridPictureDao {
    @Query("SELECT * FROM GRID_PICTURE")
    fun getAll(): List<GridPicture>

    //@Query("SELECT * FROM GRID_PICTURE WHERE id IN (:ids)")
    //fun loadAllByIds(ids: IntArray): List<GridPicture>

    //@Query("SELECT * FROM GRID_PICTURE WHERE id = (:id) LIMIT 1")
    //fun queryById(id: Long): GridPicture?

    @Query("SELECT * FROM GRID_PICTURE WHERE bookNoteId = (:bookNoteId)")
    fun queryByBookNoteId(bookNoteId: Long): List<GridPicture>

    @Query("SELECT * FROM GRID_PICTURE WHERE pageserial LIKE (:pageserial) LIMIT 1")
    fun queryByPageserial(pageserial: String): GridPicture?

    @Query("SELECT * FROM GRID_PICTURE WHERE bookNoteId = (:bookNoteId) AND pageNumber = (:pageNumber) LIMIT 1")
    fun queryByBookNoteIdAndPageNumber(bookNoteId: Long, pageNumber:Int): GridPicture?


    @Insert
    fun insertAll(vararg gridPictures: GridPicture)

    @Insert(onConflict = OnConflictStrategy.REPLACE) //如果有相同的id就替换； ABORT默认这个，如果相同，会报错
    fun insertGridPicture(vararg gridPictures: GridPicture)

    @Delete
    fun delete(gridPictures: GridPicture)

    @Delete
    fun deleteAll(vararg gridPictures: GridPicture)

    @Update
    fun updateGridPictures(vararg gridPictures: GridPicture)

}